import * as types from '../mutation-types';
import Vue from 'vue';
import Tools from '@/utils/Tools.js';
import { ChatIM } from '@/utils/IM.js'
const state = {
	IMEntity: null
}

const mutations = {
	[types.INIT_IM_SERVICE](state) {
		if (Tools.checkIsLogin()) {
			state.IMEntity = new ChatIM(Tools.checkIsLogin());
		}
	},
	[types.DISCONNECT_IM_SERVICE](state) {
		if (state.IMEntity) {
			state.IMEntity.close({
				complete: () => {
					state.IM = null;
				}
			});
		}
	},
	[types.RECONNECTION_IM_SERVICE](state, force = false) {
		if (state.IMEntity) {
			state.IMEntity.reconnection(force)
		}
	}
}



export default {
	state,
	mutations
}
